home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 9166 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: library.erc.clarkson.edu!rpi!not-for-mail
  2. From: wcowley@cftnet.com (Wes Cowley)
  3. Newsgroups: comp.lang.c++.moderated,comp.lang.c++
  4. Subject: Re: Simple inheritance Q
  5. Followup-To: comp.lang.c++.moderated,comp.lang.c++
  6. Date: 28 Feb 1996 13:11:32 -0000
  7. Organization: CFTnet
  8. Sender: cppmods@netlab.cs.rpi.edu
  9. Approved: devitto@ferndown.ate.slb.com
  10. Message-ID: <4h1ka4$7qk@netlab.cs.rpi.edu>
  11. References: <4gumo0$hta@netlab.cs.rpi.edu>
  12. NNTP-Posting-Host: netlab.cs.rpi.edu
  13. X-Original-Date: 28 Feb 1996 10:11:20 GMT
  14.  
  15. Eric Simon (erics@access2.digex.net) wrote:
  16. : 1.    Animal *p;
  17. : 2.    Cat a(args);
  18. : 3.    p = &a;
  19. : Now, if I define
  20. :     class Cat:Animal{...
  21. : then I get the error in line 3:
  22. :   Can not convert Cat * to Animal *
  23. : But if I define
  24. :    class Cat:public Animal{...
  25. : everything is fine.
  26. : Can anyone tell me why?
  27.  
  28. Inheritance defaults to private, which essentially means that if you use:
  29.  
  30.    class Cat : Animal { ...
  31.  
  32. code outside your Cat class has no way of knowing that Cat inherits from 
  33. Animal and cannot use the implicit conversion from Cat* to Animal*. 
  34.  
  35. Wes
  36.  
  37.       [ Articles to moderate: mailto:c++-submit@netlab.cs.rpi.edu ]
  38.       [  Read the C++ FAQ: http://www.connobj.com/cpp/cppfaq.htm  ]
  39.       [  Moderation policy: http://www.connobj.com/cpp/guide.htm  ]
  40.       [      Comments? mailto:c++-request@netlab.cs.rpi.edu       ]
  41.